$(function () { function refreshCaptcha() { var $captcha = $('.js-captcha'); var timestamp = new Date().getTime(); var src = $captcha.attr('src'); $captcha.attr('src', src + '?' + timestamp); } function checkIsValidDomain(domain) { if (domain.indexOf(".") === -1) { return false; } var re = new RegExp(/^(?!:\/\/)([a-zA-Zа-я0-9]+\.)?[a-zA-Zа-я0-9][a-zA-Zа-я0-9-]+\.[a-zA-Zа-я]{2,6}?$/i); return domain.match(re); } $(window).on('resize', function () { $('.js-nav').toggle($(document).width() > 946) }); $('.js-nav-btn').on('click', function() { $(this).toggleClass('nav-btn_close'); $('.js-nav').toggle(); }); $('.spoiler-link').on('click', function(e) { e.preventDefault(); $(this).toggleClass('spoiler-link_active').next('.spoiler-txt').slideToggle(); }); $('.js-btn-search').on('click', function() { var domain = $('#domainSearch').val(); var url = $(this).data('url'); $('.js-search-error-alert, .js-search-result').html(''); if (checkIsValidDomain(domain)) { $.ajax({ type: 'GET', url: url, data: {fqdn: domain}, success: function (response) { $('.js-search-result').html('
' + response + '
').show(); }, error: function () { $('.js-search-error-alert').html('Ошибка при получении Whois-информации'); } }); } else { $('.js-search-error-alert').html('Введено неверное значение'); } }); $('#domainSearch').on('click', function () { $('.js-search-error-alert, .js-search-result').html(''); }); $('.js-news-title').on('click', function () { $('.js-news-title').removeClass('news-title_active'); $(this).addClass('news-title_active'); var itemId = $(this).data('title'); $('.js-news-item').each(function () { var $item = $(this); if ($item.data('item') === itemId) { $item.show(); } else { $item.hide(); } }); }); $('#sendData').submit(function(e) { var $form = $(this); var emptyFields = 0; $('.js-register-input').each(function () { var field = $(this).attr('name'); if (!$(this).val()) { var msg = $('label[for="' + field + '"]').html(); $('[name="' + field + '"]').addClass('base-input_error'); $('[data-name="' + field + '"]').html('Пожалуйста, введите ' + msg + '').show(); emptyFields++; } }); if (!emptyFields) { $.ajax({ type: 'POST', url: $form.attr('action'), data: $form.serialize(), success: function (response) { if (response.result === 'success') { if (response.msg) { $('.popup .popup__msg').html(response.msg); } $('.popup').fadeIn(300).delay(2500).fadeOut(300); $('.js-register-input').val(''); } else if (response.errors) { $('.js-register-input').each(function () { var item = $(this).attr('name'); if (typeof response.errors[item] !== "undefined") { $('[name="' + item + '"]').addClass('base-input_error'); $('[data-name="' + item + '"]').html('Введено неверное значение').show(); } }); } else { if (response.msg) { $('.popup .popup__msg').html(response.msg); } $('.popup').fadeIn(300).delay(2500).fadeOut(300); } }, error: function () { $('.popup .popup__msg').html('Произошла ошибка, попробуйте позже.'); $('.popup').fadeIn(300).delay(2500).fadeOut(300); }, complete: function () { if (typeof grecaptcha !== 'undefined') { grecaptcha.reset(); } } }); refreshCaptcha(); } e.preventDefault(); }); $('.js-register-input').on('focus', function () { var item = $(this).attr('name'); $('[name="' + item + '"]').removeClass('base-input_error'); $('[data-name="' + item + '"]').hide(); }); $('.js-captcha-link').on('click', function() { refreshCaptcha(); }); });